import { SUCCESS, BAD_REQUEST, UNAUTHORIZED, FORBIDDEN, NOT_FOUND, INTERNAL_SERVER_ERROR } from './statusCodes'

const status =  {
  SUCCESS: 200,
  CREATED: 201,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  CONFLICT: 409,
  INTERNAL_SERVER_ERROR: 500,
};

export default {
  success: async (data = null, options = {}) => {
    return {
      code: SUCCESS,
      data,
      message: "请求成功",
      ...options
    }
  },
  error: (message = '请求失败', data = null, options = {}) => {
    return {
      code: BAD_REQUEST,
      message,
      data,
      ...options
    }
  },
  unauthorized: (message = '未授权', data = null, options = {}) => {
    return {
      code: UNAUTHORIZED,
      message,
      data,
      ...options,
    };
  },
  forbidden: (message = '禁止访问', data = null, options = {}) => {
    return {
      code: FORBIDDEN,
      message,
      data,
      ...options,
    };
  },
  notFound: (message = '资源未找到', data = null, options = {}) => {
    return {
      code: NOT_FOUND,
      message,
      data,
      ...options,
    };
  },
  internalServerError: (message = '服务器内部错误', data = null, options = {}) => {
    return {
      code: INTERNAL_SERVER_ERROR,
      message,
      data,
      ...options,
    };
  }
}